package com.samon.config;
/*
               _.---..._
           ./^         ^-._
         ./^C===.         ^\.   /\
        .|'     \\        _ ^|.^.|
   ___.--'_     ( )  .      ./ /||
  /.---^T\      ,     |     / /|||
 C'   ._`|  ._ /  __,-/    / /-,||
      \ \/    ;  /O  / _    |) )|,
       i \./^O\./_,-^/^    ,;-^,'
        \ |`--/ ..-^^      |_-^
         `|  \^-           /|:
          i.  .--         / '|.
           i   =='       /'  |\._
         _./`._        //    |.  ^-ooo.._
  _.oo../'  |  ^-.__./X/   . `|    | d
				 比克叔叔保佑
				 代码无BUG!
 */

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * 2.0以下版本继承AbstractWebSocketMessageBrokerConfigurer 类
 * 
 * @author Mr.Wu on 2018/9/7
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

	/**
	 * 注册一个 Stomp 协议的 endpoint, 指定url为 "alarm", 设置跨域, 指定 SockJS协议
	 * 
	 * @param registry
	 */
	@Override public void registerStompEndpoints(StompEndpointRegistry registry) {
		registry.addEndpoint("/alarm").setAllowedOrigins("*").withSockJS();
	}

	/**
	 * 配置消息代理, 将消息回传给"/topic"开头的客户端
	 * 
	 * @param registry
	 */
	@Override public void configureMessageBroker(MessageBrokerRegistry registry) {
		registry.enableSimpleBroker("/topic");
	}
}
